/**
 * 双指针
*/ 
const removeNthFromEnd = (head, n) => {
  if (head == null || head.next == null) return null
  const newHead = new ListNode(0)
  newHead.next = head
  let i = 0, left = newHead, right = newHead
  while (i < n) {
    right = right.next
    i++
  }
  while (right.next) {
    left = left.next
    right = right.next
  }
  left.next = left.next.next

  return newHead.next
}

const head = {
  val: 1,
  next: {
    val: 2,
    // next: null
    next: {
      val: 3,
      next: {
        val: 4,
        next: {
          val: 5,
          next: {
            val: 6,
            next: null
          }
        }
      }
    }
  }
}

console.log(removeNthFromEnd(head, 6));